<template>
  <div class="musiclist">
    <div class="topArea">
      <div
        class="topCover"
        :style="{backgroundImage: 'url('+playlistDetail.coverImgUrl+'?param=170y170)'}"
      >
        <!-- https://p1.music.126.net/JT4CCJ9Ox7bf4XSQQ9WLJg==/109951164787708537.jpg?imageView=1&type=webp&thumbnail=379x0 -->
        <div
          class="leftCover"
          :style="{backgroundImage: 'url('+playlistDetail.coverImgUrl+'?imageView=1&type=webp&thumbnail=379x0)'}"
        >
          <div class="count">{{playlistDetail.playCount | formatPlayCount}}</div>
        </div>
        <div class="rightInfo">
          <div class="title">{{playlistDetail.title}}</div>
          <div class="author">
            <!-- http://p1.music.126.net/q80YhtM8Yn3bEgugE3T-Cg==/109951163721382420.jpg?imageView=1&type=webp&thumbnail=91x0 -->
            <div
              class="authorIcon"
              :style="{backgroundImage: 'url('+playlistDetail.avatarUrl+'?imageView=1&type=webp&thumbnail=91x0)'}"
            ></div>
            <div class="authorName">{{playlistDetail.nickname}}</div>
          </div>
        </div>
      </div>

      <div class="allDsc" @click="shrinkAllDsc" :class="{shrinkAllDsc: haveShrink}">
        <div class="label">
          标签:&nbsp;&nbsp;
          <div class="labelItem" v-for="(item,index) in playlistDetail.tags" :key="index">{{item}}</div>
        </div>
        <div
          class="introduction"
          :class="{shrinkIntroduction: haveShrink}"
          v-html="playlistDetail.description"
        ></div>
        <!-- <div
          class="dsc"
          :class="{shrinkDsc: haveShrink}"
        >放克(Funk)是一种美国的音乐类型，起源于1960年代中期至晚期，非裔美国人音乐家将灵魂乐、灵魂爵士乐和节奏蓝调融合成一种有节奏的、适合跳舞的音乐新形式。放克“不再强调旋律与和声，而强调电贝斯与鼓的强烈节奏律动”。放克歌曲通常建立在单一和弦上的衍伸性即席伴奏，不同于节奏蓝调和灵魂乐围绕在和弦进行(chord progression)。</div>
        <div class="tips">歌单收录国内融入funk的歌曲，以乐队和独立音乐人为主，Let’s get funky，加入放克舞厅一起跟随律动跳舞吧！</div>-->
      </div>

      <div class="musicListKey">歌曲列表</div>
      <songs
        :musicList="musicList"
        :showIndex="true"
        :showPrimaryIndex="false"
        v-if="musicList.length"
      />
    </div>
  </div>
</template>
 
<script>
import { getPlaylistDetail } from "@/api/playlist";
import { formatPlayCount } from "@/utils/filters/count.js";
import songs from "@/components/admin/adminList/songs";
export default {
  name: "vueName",
  props: {
    id: {
      type: String
    }
  },
  components: {
    songs
  },
  filters: {
    formatPlayCount
  },
  async created() {
    const res = await getPlaylistDetail(this.id);
    const tracks = res.data.playlist.tracks;
    // console.log(res);
    const playlist = res.data.playlist;
    this.playlistDetail = {
      title: playlist.name,
      coverImgUrl: playlist.coverImgUrl,
      playCount: playlist.playCount,
      avatarUrl: playlist.creator.avatarUrl,
      nickname: playlist.creator.nickname,
      tags: playlist.tags,
      description: playlist.description.replace(/\n/g, "<br/>")
    };
    console.log(this.playlistDetail);
    tracks.forEach((item, index) => {
      this.musicList[index] = {
        title: item.name,
        dsc: item.al.name,
        al: item.alia[0],
        id: item.id,
        picUrl: item.al.picUrl
      };
      let authors = [];
      item.ar.forEach((item1, index1) => {
        authors.push(item1.name);
      });
      this.musicList[index].authors = authors.join("/");
    });
    this.$forceUpdate();
    // console.log(this.musicList)
  },
  methods: {
    shrinkAllDsc() {
      this.haveShrink = !this.haveShrink;
    }
  },
  data() {
    return {
      haveShrink: true,
      musicList: [],
      playlistDetail: {}
    };
  }
};
</script>
 
<style scoped lang = "scss">
* {
  flex-shrink: 0;
}
.musiclist {
  .topArea {
    width: 100%;
  }
  .topCover {
    width: 100%;
    height: 186px;
    padding: 30px 10px 30px 15px;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    background-position: 50%;
    /* background-image: url("http://p4.music.126.net/JT4CCJ9Ox7bf4XSQQ9WLJg==/109951164787708537.jpg"); */
    background-size: cover;
    z-index: -3;
    display: flex;
    justify-content: space-between;
    /* align-items: center; */
    &::after {
      content: "";
      position: absolute;
      background-position: 50%;
      background-size: cover;
      background-image: inherit;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      transform: scale(1.5);
      z-index: -2;
      filter: blur(20px);
      overflow: hidden;
    }
    &::before {
      content: "";
      position: absolute;
      background-color: rgba($color: #000, $alpha: 0.2);
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      z-index: -1;
    }
    .leftCover {
      /* background-image: url("http://p4.music.126.net/JT4CCJ9Ox7bf4XSQQ9WLJg==/109951164787708537.jpg?param=170y170"); */
      background-size: contain;
      background-repeat: no-repeat;
      width: 126px;
      padding-top: 100%;
      position: relative;
      &::before {
        content: "歌单";
        position: absolute;
        top: 10px;
        left: 0;
        height: 17px;
        color: #fff;
        font-size: 9px;
        padding: 0px 8px;
        border-top-right-radius: 17px;
        border-bottom-right-radius: 17px;
        text-align: center;
        line-height: 17px;
        background-color: rgba($color: $primary, $alpha: 0.8);
      }
      .count {
        color: #fff;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 18px;
        z-index: 9;
        background-image: linear-gradient(
          90deg,
          rgba(0, 0, 0, 0),
          rgba(0, 0, 0, 0.2)
        );
        display: flex;
        justify-content: flex-end;
        align-items: center;
        &::before {
          content: "";
          width: 100%;
          height: 18px;
          display: block;
          z-index: 999;
          width: 16px;
          height: 14px;
          background-size: contain !important;
          background: url("~assets/img/earphone.png") no-repeat;
        }
      }
    }
    .rightInfo {
      height: 100%;
      flex: 1;
      margin-left: 16px;
      .title {
        padding-top: 1px;
        font-size: 17px;
        color: #fefefe;
        height: 44px;
        @include ellipsis(2);
      }
      .author {
        flex: 1;
        margin-top: 20px;
        display: flex;
        align-items: center;
        .authorIcon {
          /* background-image: url("http://p1.music.126.net/q80YhtM8Yn3bEgugE3T-Cg==/109951163721382420.jpg?imageView=1&type=webp&thumbnail=91x0"); */
          background-size: contain;
          border-radius: 50%;
          width: 30px;
          height: 30px;
          position: relative;
          &::after {
            content: "";
            position: absolute;
            background-image: url("http://s3.music.126.net/mobile-new/img/usericn_3x.png?71c26f814f7ee3c5594694c1b6234ea8=");
            background-size: 70px auto;
            background-position: -40px 0;
            width: 12px;
            height: 12px;
            bottom: 0;
            right: -5px;
          }
        }
        .authorName {
          max-width: 150px;
          color: hsla(0, 0%, 100%, 0.7);
          font-size: 14px;
          line-height: 30px;
          margin-left: 5px;
          /* @include ellipsis(1); */
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
      }
    }
  }
  .shrinkAllDsc {
    height: 90px;
    &::after {
      transform: rotate(180deg) translateY(8px);
    }
  }
  .allDsc {
    padding: 10px 10px 18px 15px;
    color: #666;
    font-size: 14px;
    position: relative;
    overflow: hidden;
    &::after {
      content: "";
      background-image: url("~assets/img/spareIcon.png");
      background-repeat: no-repeat;
      background-size: contain;
      width: 13px;
      height: 13px;
      position: absolute;
      right: 12px;
      bottom: 2px;
    }
    .label {
      height: 22px;
      margin-bottom: 7px;
      overflow: hidden;
      .labelItem {
        display: inline-block;
        margin-right: 10px;
        padding: 1px 8px;
        font-size: 12px;
        border-radius: 12px;
        border: 1px rgba($color: #ccc, $alpha: 0.3) solid;
        margin-bottom: 5px;
      }
    }
    .introduction {
      margin-bottom: 18px;
      &::before {
        content: "简介:\00A0\00A0\00A0\00A0";
      }
    }
    .shrinkIntroduction {
      @include ellipsis(3);
    }
    /* .dsc {
      margin-bottom: 18px;
    }
    .shrinkDsc {
      @include ellipsis(1);
      margin-bottom: 22px;
    }
    .tips {
    } */
  }
  .musicListKey {
    box-sizing: border-box;
    width: 100%;
    height: 23px;
    line-height: 23px;
    padding: 0 10px;
    font-size: 12px;
    color: #666;
    background-color: #eeeff0;
  }
}
</style>